<template>
  <div>

    <el-row :gutter="20">
      <el-col :xs="12" :sm="12" :lg="24" class="card-panel-col">
        <el-button type="primary">
          关键指标总数
        </el-button>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              累计注册用户总数
            </div>
            <count-to :start-val="0" :end-val="totalData.userCount" :duration="2600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('messages')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              累计回收订单量
            </div>
            <count-to :start-val="0" :end-val="totalData.orderCount" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              已完成回收订单数量
            </div>
            <count-to :start-val="0" :end-val="totalData.doneOrderCount" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('shoppings')">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              已完成回收订单总额
            </div>
            <count-to :start-val="0" :end-val="totalData.doneOrderAmount" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>

      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('shoppings')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              出库回收订单量
            </div>
            <count-to :start-val="0" :end-val="totalData.outboundOrderCount" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>

      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('shoppings')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              出库总克重
            </div>
            <count-to :start-val="0" :end-val="totalData.totalWeight" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>

    </el-row>


    <el-row :gutter="20">
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <el-button type="primary">漏斗指标数据</el-button>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col" style="text-align: right">
        <el-dropdown split-button type="primary" @command="handleClick">
          {{currentTime}}
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="0">今天</el-dropdown-item>
            <el-dropdown-item command="1">本周</el-dropdown-item>
            <el-dropdown-item command="2">本月</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              回收订单数
            </div>
            <count-to :start-val="0" :end-val="funnelData.inOrderCount" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              检测订单数
            </div>
            <count-to :start-val="0" :end-val="funnelData.inCheckOrderCount" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              估价订单数
            </div>
            <count-to :start-val="0" :end-val="funnelData.inExpectPriceCount" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="20">
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col" style="margin-bottom: 18px;">
        <el-button type="primary">近30天数据趋势</el-button>
      </el-col>
    </el-row>

  </div>

</template>

<script>
import CountTo from 'vue-count-to'
import * as IndexApi from '@/api/system/index';

export default {
  components: {
    CountTo
  },
  data() {
    return {
      currentTime: '今天',
      type: 0,
      totalData: {
        /**
         *用户总数
         */
        userCount: 0,
        /**
         *回收订单总数
         */
        orderCount: 0,
        /**
         *已完成回收订单总数
         */
        doneOrderCount: 0,
        /**
         *已完成回收订单总额
         */
        doneOrderAmount: 0,

        /**
         *出库回收订单总数
         */
        outboundOrderCount: 0,
        /**
         * 出库总克重
         */
        totalWeight: 0,
      },
      funnelData: {
        /**
         *回收订单数
         */
        inOrderCount: 0,
        /**
         *检测订单数
         */
        inCheckOrderCount: 0,
        /**
         * 估价订单
         */
        inExpectPriceCount: 0,
      }
    }
  },
  created() {
    this.getTotalData()
    this.getFunnelData(0)
  },
  computed: {
  },
  methods: {
    async getTotalData() {
      try {
        const res = await IndexApi.getTotalData();
        this.totalData = res.data
      } finally {
      }
    },
    async getFunnelData(type) {
      try {
        const res = await IndexApi.getFunnelData(type);
        this.funnelData = res.data
      } finally {
      }
    },
    handleClick(command) {
      const map = {
        0: '今天',
        1: '本周',
        2: '本月'
      };
      this.currentTime = map[command] || '今天';
      console.log("type:::", command)
      this.getFunnelData(command)
    },
    handleSetLineChartData(type) {
      // this.$emit('handleSetLineChartData', type)
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 24px 0 0 14px;
      padding: 6px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      // float: right;
      font-weight: bold;
      margin: 26px 12px 26px 0;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
